import math
from typing import List


class Solution:
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        def start_search(nums, target, lenght):
            left = -1
            right = lenght
            while left + 1 != right:
                mid = math.floor((left + right) / 2)
                if nums[mid] >= target:
                    right = mid
                else:
                    left = mid
            return right

        def end_search(nums, target, lenght):
            left = -1
            right = lenght
            while left + 1 != right:
                mid = math.floor((left + right) / 2)
                if nums[mid] < target + 1:
                    left = mid
                else:
                    right = mid
            return left

        if not nums:
            return [-1, -1]

        lenght = len(nums)
        pos1 = start_search(nums, target, lenght)
        pos2 = end_search(nums, target, lenght)
        if (
            0 <= pos1 < lenght
            and 0 <= pos2 < lenght
            and nums[pos1] == target
            and nums[pos2] == target
        ):
            return [pos1, pos2]
        return [-1, -1]


if __name__ == "__main__":
    nums = [5, 7, 7, 8, 8, 10]
    target = 8
    a = Solution()
    print(a.searchRange(nums, target))
